package com.tyk.bookstore.front.storage.service.impl;


import com.tyk.bookstore.front.common.core.util.ObjUtil;
import com.tyk.bookstore.front.storage.model.dto.StockMeetDto;
import com.tyk.bookstore.front.storage.model.query.Stock4OrderDeductQuery;
import com.tyk.bookstore.front.storage.model.query.Stock4OrderRollBackQuery;
import com.tyk.bookstore.front.storage.model.query.Stock4OrderStockMeetQuery;
import com.tyk.bookstore.front.storage.repository.StockRepository;
import com.tyk.bookstore.front.storage.service.StockApiService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
@RequiredArgsConstructor
public class StockApiServiceImpl implements StockApiService {

    private final StockRepository stockRepository;

    @Override
    public void rollBack(List<Stock4OrderRollBackQuery> rbqList) {
        if (ObjUtil.isEmpty(rbqList)) return;
        stockRepository.rollBack(rbqList);
    }

    @Override
    public void deduct(List<Stock4OrderDeductQuery> dpList) {
        if (ObjUtil.isEmpty(dpList)) return;
        stockRepository.deduct(dpList);
    }

    @Override
    public List<StockMeetDto> getStockMeetListWithStrict(List<Stock4OrderStockMeetQuery> smqList) {
        if (ObjUtil.isEmpty(smqList)) return new ArrayList<>();
        return stockRepository.selectStockMeetListWithStrict(smqList);
    }

}
